package com.yaozheng.vocationaltraining.view.userinfo;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * 勋章
 */
@EViewGroup(R.layout.item_my_user_info_medals_data)
public class ItemMyUserInfoMedalsDataView extends LinearLayout {
    @ViewById
    ImageView medalBrandImage, medalGoodsImage, medalImage, medalRepairImage, medalSalesImage, medalServiceImage;
    @ViewById
    TextView itemMyUserInfoDataName;

    public ItemMyUserInfoMedalsDataView(Context context) {
        super(context);
    }

    public ItemMyUserInfoMedalsDataView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 加载数据
     *
     * @param position
     * @param itemData
     */
    public void loadData(int position, JSONObject itemData) {
        JSONArray medals = TypeUtils.getJsonArray(itemData, "value");
        itemMyUserInfoDataName.setText(TypeUtils.getJsonString(itemData, "showValue"));
//            //品牌大师
//            medalBrandImage.setVisibility(View.GONE);
        medalBrandImage.setAlpha(0x5A);
////            商品大师
//            medalGoodsImage.setVisibility(View.GONE);
        medalGoodsImage.setAlpha(0x5A);
////              形象大师
//            medalImage.setVisibility(View.GONE);
        medalImage.setAlpha(0x5A);
////             维保大师
//            medalRepairImage.setVisibility(View.GONE);
        medalRepairImage.setAlpha(0x5A);
////            	销售大师
//            medalSalesImage.setVisibility(View.GONE);
        medalSalesImage.setAlpha(0x5A);
////            服务大师
//            medalServiceImage.setVisibility(View.GONE);
        medalServiceImage.setAlpha(0x5A);
        for (int i = 0; i < TypeUtils.getJsonArraySize(medals); i++) {
//                1	形象大师
//                2	维保大师
//                3	服务大师
//                4	销售大师
//                5	商品大师
//                6	品牌大师
            int itemMedal = TypeUtils.getJsonInteger(medals, i);
            if (itemMedal == 1) {
                medalImage.setAlpha(0xFF);

            } else if (itemMedal == 2) {
                medalRepairImage.setAlpha(0xFF);
            } else if (itemMedal == 3) {
                medalServiceImage.setAlpha(0xFF);
            } else if (itemMedal == 4) {
                medalSalesImage.setAlpha(0xFF);
            } else if (itemMedal == 5) {
                medalGoodsImage.setAlpha(0xFF);
            } else if (itemMedal == 6) {
                medalBrandImage.setAlpha(0xFF);
            }
        }
    }
}
